import scrapy

from ScrapyObject.spiders.utils.url_utils import *

'''
scrapy crawl ydaw -o ydaw.json
http://www.98vq.asia/
http://www.98vq.asia/
'''


class YdawSpider(scrapy.Spider):
    name = "ydaw"
    # 前缀
    prefix = 'http://www.'
    # 中缀
    website = '98vq'
    # 后缀
    suffix = '.asia/'
    allowed_domains = [website + '.asia']
    start_urls = [prefix + website + suffix]

    def __init__(self):
        self.i = 0

    def parse(self, response):
        content = get_data(response)
        video_url = get_video_url_one(content)
        picture_url = response.xpath("//td[@class='t_f']//img/@ file").extract()
        tags = response.xpath("//div[@class='z']//a/text()").extract()
        if len(video_url) and len(picture_url) and len(tags):
            self.i = self.i + 1
            yield get_video_item(id=self.i, tags=tags[-3], url="", name=tags[-2], pUrl=picture_url[0], vUrl=video_url[0])
        url_list = get_url(content)
        for url in url_list:
            if url.startswith('/') or url.endswith('.html'):
                yield scrapy.Request(split_joint(self.prefix + self.website + self.suffix, url), callback=self.parse)
